#include "MCPanController.h"

MCPanController::MCPanController(ICanvas *presenter) :
    _presenter(presenter),
    _isPanningValid(false)
{
}

void MCPanController::onMouseDown(IMouseArgs &args)
{
    if (args.isMiddleMousePressed())
    {
        _startDraggingPos = args.position();
        _isPanningValid = true;
    }
}

void MCPanController::onMouseUp(IMouseArgs &args)
{
    _isPanningValid = false;
}

void MCPanController::onMouseMove(IMouseArgs &args)
{
    if (_isPanningValid)
    {
        MCPoint2D deltaPos = args.position() - _startDraggingPos;
        _presenter->setDrawingOffset(deltaPos * _presenter->scale());
        _startDraggingPos = args.position();
    }
}
